#include "SQLQueryExpr.h"
#include "../../visitor/SQLASTVisitor.h"

SQLQueryExpr::SQLQueryExpr()
{
}

SQLQueryExpr::~SQLQueryExpr()
{
  // if (subQuery != nullptr)
  // {
  //   // delete subQuery;
  //   subQuery = nullptr;
  // }
}
SQLQueryExpr::SQLQueryExpr(SQLSelect_ptr theSelect)
{
  setSubQuery(theSelect);
}

SQLSelect_ptr SQLQueryExpr::getSubQuery()
{
  return subQuery;
}

void SQLQueryExpr::setSubQuery(SQLSelect_ptr theSubQuery)
{
  if (theSubQuery != NULL)
  {
    theSubQuery->setParent(SharedObject(SQLQueryExpr));
  }
  subQuery = theSubQuery;
}

void SQLQueryExpr::output(std::stringstream * buf)
{
  subQuery->output(buf);
}

void SQLQueryExpr::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLQueryExpr)))
  {
    acceptChild(visitor, (subQuery));
  }

  visitor->endVisit(SharedObject(SQLQueryExpr));
}

// int SQLQueryExpr::hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((subQuery == NULL) ? 0 : subQuery.hashCode());
// return result;
//}

// BOOL_ptr SQLQueryExpr::equals(Object obj) {
// if (this == obj) {
// return BOOL::TRUE;
//}
// if (obj == NULL) {
// return BOOL::FALSE;
//}
// if (getClass() != obj.getClass()) {
// return BOOL::FALSE;
//}
// SQLQueryExpr other = (SQLQueryExpr) obj;
// if (subQuery == NULL) {
// if (other.subQuery != NULL) {
// return BOOL::FALSE;
//}
//} else if (!subQuery.equals(other.subQuery)) {
// return BOOL::FALSE;
//}
// return BOOL::TRUE;
//}
